﻿using System.Diagnostics.Contracts;

namespace BlindData
{
	/// <summary>
	/// Generator interface.
	/// </summary>
	[ContractClass(typeof(GeneratorContract))]
	public interface IGenerator
	{
		/// <summary>
		/// Returns a nonnegative random number.
		/// </summary>
		/// <returns>A 32-bit signed integer greater than or equal to zero and less than System.Int32.MaxValue.</returns>
		int Next();
		/// <summary>
		/// Fills the elements of a specified array of bytes with random numbers.
		/// </summary>
		/// <param name="buffer">An array of bytes to contain random numbers.</param>
		void NextBytes(byte[] buffer);
		/// <summary>
		/// Returns a random number between 0.0 and 1.0.
		/// </summary>
		/// <returns>A double-precision floating point number greater than or equal to 0.0, and less than 1.0.</returns>
		Probability NextProbability();
	}

	//Code Contract
	internal sealed class GeneratorContract : IGenerator
	{
		public int Next()
		{
			Contract.Ensures(Contract.Result<int>() >= 0);
			return default(int);
		}

		public void NextBytes(byte[] buffer)
		{
			Contract.Requires(buffer != null);
		}

		public Probability NextProbability()
		{
			return default(Probability);
		}
	}
}
